package com.boyaa.shells.tool 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author fly
	 */
	public class DoubleButton
	{
		private var _bt:MovieClip = null;
		private var _fun:Function = null;
		public function DoubleButton(bt:MovieClip, fun:Function) 
		{
			_bt = bt;
			_bt.stop();
			_fun = fun;
		}
		
		public function init():void
		{
			_bt.gotoAndStop(1);
		}
		
		public function addEvent():void
		{
			_bt.mouseEnabled = true;
			_bt.buttonMode = true;
			_bt.addEventListener(MouseEvent.ROLL_OVER, rollOver);
			_bt.addEventListener(MouseEvent.ROLL_OUT , rollOut);
			_bt.addEventListener(MouseEvent.CLICK, onClick);
			
		}
		
		public function removeEvent():void
		{
			_bt.mouseEnabled = false;
			_bt.buttonMode = false;
			_bt.removeEventListener(MouseEvent.ROLL_OVER, rollOver);
			_bt.removeEventListener(MouseEvent.ROLL_OUT , rollOut);
			_bt.removeEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onClick(e:MouseEvent):void 
		{
			e.stopPropagation();
			if (int(_bt.currentFrame / 3))
			{
				_bt.gotoAndStop(2);
				_fun(1);
			}
			else
			{
				_bt.gotoAndStop(5);
				_fun(0);
			}
		}
		
		private function rollOut(e:MouseEvent):void 
		{
			if (_bt.currentFrame == 1)
				return;
			if (_bt.currentFrame == 4)
				return;
			_bt.prevFrame();
		}
		
		private function rollOver(e:MouseEvent):void 
		{
			_bt.nextFrame();
		}
		
	}

}